from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app
import os
from google.appengine.ext.webapp import template

class MainPage(webapp.RequestHandler):
    def get(self):    
        template_values = {}    
        path = os.path.join(os.path.dirname(__file__), 'index.html')
        self.response.out.write(template.render(path, template_values))

class AddTwoNumbers(webapp.RequestHandler):
    def get(self):
        try:
            first = int(self.request.get('first'))
            second = int(self.request.get('second'))
            self.response.out.write("<html><body><p>%d + %d = %d</p></body></html>" %
                              (first, second, first + second))
        except (TypeError,ValueError):
            self.response.out.write("<html><body><p>Invalid inputs</p></body></html>")
            

application = webapp.WSGIApplication([('/', MainPage),
                                      ('/AddTwoNumbers',AddTwoNumbers)],
                                     debug=True)

def main():
  run_wsgi_app(application)

if __name__ == "__main__":
  main()